<?php

namespace App\Observers;

use App\Models\HouseBroker;
use App\Tools\RedisTools;

class BrokerObserver
{
    /**
     * Handle the HouseBroker "created" event.
     *
     * @param  \App\Models\HouseBroker  $houseBroker
     * @return void
     */
    public function created(HouseBroker $houseBroker)
    {
        //
//        模型监听，创建经纪人的时候加入排行榜的redis
        $redis = RedisTools::getInstance()->connectRedis();
        HouseBroker::where('id',$houseBroker->id)->update([
            'broker_image'=>"http://shx.zxh666.top/".$houseBroker->broker_image
        ]);
//        $data = [
//          'id'=>$houseBroker->id,
//          'broker_name'=>$houseBroker->broker_name,
//          'broker_image'=>"http://shx.zxh666.top/".$houseBroker->broker_image
//        ];

        $redis->zAdd('rankingList',$houseBroker->sales_volume,$houseBroker->id);


    }

    /**
     * Handle the HouseBroker "updated" event.
     *
     * @param  \App\Models\HouseBroker  $houseBroker
     * @return void
     */
    public function updated(HouseBroker $houseBroker)
    {
        //

    }

    /**
     * Handle the HouseBroker "deleted" event.
     *
     * @param  \App\Models\HouseBroker  $houseBroker
     * @return void
     */
    public function deleted(HouseBroker $houseBroker)
    {
        //
    }

    /**
     * Handle the HouseBroker "restored" event.
     *
     * @param  \App\Models\HouseBroker  $houseBroker
     * @return void
     */
    public function restored(HouseBroker $houseBroker)
    {
        //
    }

    /**
     * Handle the HouseBroker "force deleted" event.
     *
     * @param  \App\Models\HouseBroker  $houseBroker
     * @return void
     */
    public function forceDeleted(HouseBroker $houseBroker)
    {
        //
    }
}
